package com.situ.day14;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.junit.Test;

public class ReflectDome {
	@Test
	public void test() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		//类路径
		Class clazz = Class.forName("com.situ.day14.XueSheng");//知道包名
		System.out.println(clazz);
		//类名
		Class clazz1 = XueSheng.class;//最简单
		System.out.println(clazz1);
		//对象
		XueSheng  xueSheng  = new XueSheng();
		Class clazz2 = xueSheng.getClass();
		System.out.println(clazz2);
		System.out.println("------------");
		
		
		
		
		//类的名字
		System.out.println(clazz.getName());
		System.out.println(clazz.getSimpleName());//名字
		System.out.println(clazz.getModifiers());//修饰符
		System.out.println("-------------");
		
		
		
		
		
		//所有的属性
		Field[] fields = clazz.getDeclaredFields();
		for (Field field : fields) {
			System.out.println(field);
		}
		System.out.println("-----------");
		
		
		//get、set方法
		Method[] methods = clazz.getDeclaredMethods();
		for (Method method : methods) {
			System.out.println(method);
		}
		System.out.println("-----------");
	
		
		
		//构造方法
//		Constructor[] constructors = clazz.getDeclaredConstructors();
//		for (Constructor constructor : constructors) {
//			System.out.println(constructor);//有参和
//			System.out.println(clazz.getName());//名字
//			XueSheng xueSheng2 = (XueSheng)constructor.newInstance();
//			System.out.println(xueSheng2);
//			
//		}
		
		
	}
}
